package com.origin.onlinesys.web.utils;

import com.origin.onlinesys.domain.modules.interviewsys.Account;
import com.origin.onlinesys.domain.modules.interviewsys.Zone;
import org.apache.shiro.SecurityUtils;

import java.util.List;

/**
 * Created by Administrator on 2015/3/8.
 */
public final class WebUtils {
    private WebUtils(){

    }

    /**
     * 获取登录账户信息
     * @return
     */
    public static Account getAccount(){
        if(SecurityUtils.getSubject().getPrincipal() == null){return new Account();}
        return (Account)SecurityUtils.getSubject().getPrincipal();
    }

    /**
     * 获取用户id
     * @return
     */
    public static String getUserId(){
        return getAccount().getId();
    }

    /**
     * 用户名称
     * @return
     */
    public static  String getUserName(){
        return getAccount().getUsername();
    }

    /**
     * 获取用户所在或选择的区域
     * @return
     */
    public static String getZoneName(){
        List<Zone> zone = getAccount().getZoneList();
        for (Zone bean:zone){
            if(bean.getId().equals(WebUtils.getAccount().getQueryZoneId()))
            return bean.getName();
        }return null;
    }
}
